package sunflower.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import sunflower.domain.User;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * @description:
 * @author: TanJingyu
 * @create: 2021-09-29 16:05
 **/
@RestController
@RequestMapping("/user")
public class UserController {

    @GetMapping
    public List<User> list(User user, HttpServletRequest request) throws InterruptedException {
        System.out.println("来了请求....user-service-list()");
        System.out.println(user);
//        TimeUnit.SECONDS.sleep(15);
        return randomGenerateUsers();
    }

//    @PostMapping
//    public Object addUser() throws InterruptedException {
//        System.out.println("来了请求....user-service-addUser()");
//        TimeUnit.SECONDS.sleep(15);
//        return true;
//    }

    private List<User> randomGenerateUsers() {
        List<User> users = new ArrayList<>(64);
        for (int i = 0; i < 64; i++) {
            users.add(new User());
        }

        return users;
    }
}
